//
//  SpecialHeaderView.swift
//  OverseasOnlineShopping
//
//  Created by 唐先才 on 16/3/9.
//  Copyright © 2016年 唐先才. All rights reserved.
//

import UIKit

class SpecialHeaderView: UICollectionReusableView {
    
    var iconView = UIImageView()
    var iconLab = UILabel()
    var backView = UIView()
    var rect: CGRect?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        createUI()
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    func createUI() {
        backView.backgroundColor = UIColor.whiteColor()
        addSubview(backView)
        iconView.frame = CGRect(x: 0, y: 0, width: WIDTH, height: HEIGHT / 3)
        backView.addSubview(iconView)
        iconLab.frame = CGRect(x: 20, y: 0, width: WIDTH - 40, height: 100)
        iconLab.font = UIFont.systemFontOfSize(15)
        iconLab.numberOfLines = 0
        iconLab.backgroundColor = UIColor.whiteColor()
        iconLab.textColor = UIColor.blackColor()
        backView.addSubview(iconLab)
    }
    
    var model: TxcModel? {
        didSet {
            guard let pic = model?.strSpecialDetailImage, content = model?.strSpecialContent else {
                print("获取图片失败")
                return
            }
            iconView.sd_setImageWithURL(NSURL(string: pic))
            iconLab.text = content
            rect = NSString(string: content).boundingRectWithSize(CGSizeMake(UIScreen.mainScreen().bounds.size.width - 40, 0), options: NSStringDrawingOptions.UsesLineFragmentOrigin, attributes: [NSFontAttributeName: UIFont.systemFontOfSize(15)], context: nil)
            iconLab.frame = CGRect(x: 20, y: iconView.frame.size.height + 10, width: (rect?.size.width)!, height: (rect?.size.height)!)
            backView.frame = CGRect(x: 0, y: 0, width: WIDTH, height: iconView.frame.height + 10 + iconLab.frame.height + 10)
        }
    }
}
